<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath();
%>
<jsp:include page="/WEB-INF/page/auth/_header.jsp"></jsp:include>
<body>
	<jsp:include page="/WEB-INF/page/auth/header.jsp"></jsp:include>
	<div id="middle">
		<jsp:include page="/WEB-INF/page/auth/menu.jsp"></jsp:include>
		<div id="right">
			<div id="sign_up_studenttb">
		        <form id="sign_up_studentForm" class="m10">
		           	 报名时间：<input name="startDate" class="easyui-datebox" data-options="width:120" />-<input name="endDate" class="easyui-datebox" data-options="width:120" />
		                              报名状态<select class="form-control1" id="status" name="status">
		            	<option value="">全部</option>
		            	<option value="001">待处理</option>
		            	<option value="000">录取</option>
		            	<option value="002">未录取</option>
		            </select>
					<input type="hidden" id="schoolId" name="schoolId" value=""/>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="searchForm('sign_up_student')">查询</a>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm('sign_up_student')">重置</a>
		            <a class="easyui-linkbutton" href="javascript:void(0)" data-options="iconCls:'icon-print'" onclick="batchPrint('sign_up_student')">批量打印</a>
		            <a class="easyui-linkbutton" href="javascript:void(0)" data-options="iconCls:'icon-save'" onclick="outExcel('sign_up_student','<%=basePath%>/sys/signUp/newStudent')">导出为EXCEL</a>
		        </form>
		    </div>
		    <table id="sign_up_studentdg">
		        <thead>
		            <tr>
		            	<th data-options="field:'id',checkbox:true"></th>
		            	<th data-options="field:'statusText',title:'报名状态' ,styler: function(value,row,index){
						                   if (value=='录取') {
						                       return 'color:#0000FF;';
						                   } 
						                   if (value=='未录取') {
						                	   return 'color:red;';
						                   }                 
						               }"></th>
						<th data-options="field:'resultMessage',title:'录取结果'"></th>
		                <th data-options="field:'studentName',title:'学生姓名'"></th>
						<th data-options="field:'studentSex',title:'学生性别'"></th>						
						<th data-options="field:'studentBirthday',title:'生日'"></th>						
						<th data-options="field:'studentIdNo',title:'证件号'"></th>
						<th data-options="field:'signGrade',title:'报读年级'"></th>
						<th data-options="field:'baseSchool',title:'原就读学校'"></th>
						<th data-options="field:'familyAddr',title:'家庭详细住址'"></th>
						<th data-options="field:'houseAddr',title:'户籍详细住址'"></th>
						<th data-options="field:'nation',title:'民族'"></th>
						<th data-options="field:'healthy',title:'健康状况'"></th>
						<th data-options="field:'fatherIsGuardian',title:'爸爸是否监护人'"></th>
						<th data-options="field:'fatherName',title:'爸爸姓名'"></th>
						<th data-options="field:'fatherPhone',title:'爸爸电话'"></th>
						<th data-options="field:'fatherCompany',title:'爸爸单位'"></th>
						<th data-options="field:'motherIsGuardian',title:'妈妈是否监护人'"></th>
						<th data-options="field:'motherName',title:'妈妈姓名'"></th>
						<th data-options="field:'motherPhone',title:'妈妈电话'"></th>
						<th data-options="field:'motherCompany',title:'妈妈单位'"></th>						
						<th data-options="field:'signUpTime',title:'报名时间',formatter:function(value,row,index){
							return getTime(value,'yyyy-MM-dd hh:mm:ss');
						}"></th>
		            </tr>
		        </thead>
		    </table>
		</div>
	</div>
	<div id="confirmBox" style="display: none;height: 'auto';">
	    <div class="col-md-12 pd20">
   			<form id="confirmForm">
   				<input type="hidden" id="type">
   				<input type="hidden" id="ids">
				<div class="form-group col-md-12 calendar-sunday" id="confirmTips"></div>
				<div class="form-group col-md-12">
					<label for="companyName">名单</label>
					<textarea rows="4" id="names" class="form-control" readonly></textarea>
				</div>
				<div class="form-group col-md-12">
					<label for="companyName">反馈结果</label>
					<textarea rows="3" id="resultMessage" class="form-control"></textarea>
				</div>
			</form>
		</div>
	    <div class="text-center pd20">
	        <a href="javascript:void(0)" class="btn btn-warning btn-xs" onclick="confirmSubmit()">确认提交</a>
	    </div>
	</div>
	
	<div id="uploadBox" style="display: none;height: 'auto';">
	    <div class="col-md-12 pd20">
   			<form id="uploadForm" novalidate="novalidate" enctype="multipart/form-data" method="post">
				<div class="form-group col-md-12" id="scoreTips">
					
				</div>
				<div class="form-group col-md-12 mt20">
					<input class="easyui-filebox form-control" id="files" name="files" style="width:250px;">
				</div>
			</form>
		</div>
	    <div class="text-center pd20">
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadCommit()" style="width: 200px;">上传</a>
	    </div>
	</div>
	<jsp:include page="/WEB-INF/page/auth/_footer.jsp"/>
	<script type="text/javascript">
		var url = basePath + "/sys/signUp/newStudent";
		var schoolId = $("#userSchoolId").val();
		$(function(){
			initSchoolIdInputValue();
			$('#files').filebox({
                buttonText: '选择文件',
                buttonAlign: 'left'
            });
			loadDategrid('sign_up_student',url);
		});
		var dbObj ;
		function initSchoolIdInputValue() {
			var schoolId = $("#userSchoolId").val();
			$("#schoolId").val(schoolId);
		}
		function loadDategrid(cf,url) {
			dgEditIndex[cf]=-1;
			var btnArr=[];
			btnArr.push({text:'批量打印',iconCls:'icon-print',handler:function(){batchPrint(cf)}},'-');
			btnArr.push({text:'选中打印',iconCls:'icon-print',handler:function(){checkPrint(cf)}},'-');
			btnArr.push({text:'取消选中',iconCls:'icon-undo',handler:function(){undo(cf)}});	
			btnArr.push({text:'录取',iconCls:'icon-ok',handler:function(){ok(cf,url)}},'-');
        	btnArr.push({text:'未录取',iconCls:'icon-no',handler:function(){no(cf,url)}},'-');
        	btnArr.push({text:'上传录取结果',iconCls:'icon-large-smartart',handler:function(){upload()}});
        	dbObj = $("#"+cf+"dg").datagrid({
				url: url + "/pageQuery",
				rownumbers: true,
				striped: true,
				border: false,
				pagination: true,
				pageSize: 30,
				fitColumns: true,
				autoRowHeight: false,
				fit: true,
				toolbar: btnArr,
				queryParams:{
					status: $("#status").val(),
					schoolId: schoolId
				},
			    onAfterEdit: function(rowIndex,rowData,changes){
			    	if($.isEmptyObject(changes)) {
			    		var dgObj=$('#'+cf+'dg');
						dgObj.datagrid('rejectChanges');
						dgEditIndex[cf]=-1;
						return;	
					}
					changes.id = rowData.id;
			    	changes.schoolId = schoolId;
			    	addmodify(changes, cf, url)
			    },
				onLoadSuccess: function(data){
			        $(".note").tooltip({
				        onShow: function () {
					        $(this).tooltip('tip').css({
					       		borderColor: '#000'
					        });
				        }
			        });
				}
			})
			var tb = $("#"+cf+"tb").html();
			if(tb) {
				$(".datagrid-toolbar").prepend(tb);
				$("#"+cf+"tb").remove();
			}
		}
		function checkPrint(cf) {
			var dgObj=$('#'+cf+'dg');
			var rows=dgObj.datagrid('getSelections');
			if(rows.length>0){
				var delIds=[];
				for(var i=0;i<rows.length;i++){
					delIds.push(rows[i].id);
				}
				window.open(basePath + "/sys/signUp/newStudent/print/" + delIds.join(","));
			}else {
				$.messager.alert('提示', "请选中行",'info');
			}
		}
		function batchPrint(cf){
			var url = basePath + "/sys/signUp/newStudent/printList?" + $('#'+cf+'Form').serialize();
			window.open(url);
		}
		
		function ok(cf,url){
			if(dgEditIndex[cf]>-1){
				$.messager.alert('提示','请先保存或取消编辑！','info');
			}else{
				var dgObj=$('#'+cf+'dg');
				var rows=dgObj.datagrid('getSelections');
				if(rows.length>0){
					var ids=[];
					var names=[];
					for(var i=0;i<rows.length;i++){
						ids.push(rows[i].id);
						names.push(rows[i].signupNo + " " + rows[i].studentName);
					}
					$("#confirmTips").html("您确认录取以下选择的学生吗？");
					$("#type").val("ok");
					$("#ids").val(ids.join(","));
					$("#names").val(names.join(","));
					$('#confirmBox').dialog({
						title : '确认录取？',
						modal : true,
						width : 600,
						top : 150,
						draggable : true,
						resizable : true,
						onClose : function() {
				   			$("#confirmTips").html("");
							$("#type").val(null);
							$("#ids").val(null);
							$("#names").val(null);
							$("#resultMessage").val(null);
						}
					}).show();
				}else{
					$.messager.alert('提示','请选择行！','error');
				}
			}
		}
		
		function no(cf,url){
			if(dgEditIndex[cf]>-1){
				$.messager.alert('提示','请先保存或取消编辑！','info');
			}else{
				var dgObj=$('#'+cf+'dg');
				var rows=dgObj.datagrid('getSelections');
				if(rows.length>0){
					var ids=[];
					var names=[];
					for(var i=0;i<rows.length;i++){
						ids.push(rows[i].id);
						names.push(rows[i].signupNo + " " + rows[i].studentName);
					}
					$("#confirmTips").html("您确认不录取以下选择的学生吗？");
					$("#type").val("no");
					$("#ids").val(ids.join(","));
					$("#names").val(names.join(","));
					$('#confirmBox').dialog({
						title : '确认不录取？',
						modal : true,
						width : 600,
						top : 150,
						draggable : true,
						resizable : true,
						onClose : function() {
				   			$("#confirmTips").html("");
							$("#type").val(null);
							$("#ids").val(null);
							$("#names").val(null);
							$("#resultMessage").val(null);
						}
					}).show();
				}else{
					$.messager.alert('提示','请选择行！','error');
				}
			}
		}
		
		function confirmSubmit() {
			var type = $("#type").val();
			var ids = $("#ids").val();
			var resultMessage = $("#resultMessage").val();
			if(resultMessage.trim() == "") {
				$.messager.alert('提示', "请填写反馈结果",'info');
				return;
			}
			$.ajax({
			   type:"POST",
			   url: url + "/" + type,
			   data:{
				   ids: ids,
				   resultMessage: resultMessage
			   },
			   success: function(r){
			   		if(r.code == '000') {
			   			$.messager.alert('提示','提交成功！','info');
			   			dbObj.datagrid('reload');
			   			$('#confirmBox').dialog('close');
			   			$("#confirmTips").html("");
						$("#type").val(null);
						$("#ids").val(null);
						$("#names").val(null);
			   			return;
			   		}
				    $.messager.alert('提示', "失败",'error');
				    undo(cf);
			    }
			});
		}
		
		var uploadBox;
		function upload() {
			uploadBox = $('#uploadBox').dialog({
				title : '上传录取结果',
				modal : true,
				width : 400,
				top : 200,
				draggable : true,
				resizable : true,
				buttons : '#btns',
				onClose : function() {
					$('#files').filebox('setValue','');
				}
			}).show();
		}
		
		function uploadCommit(){
			var fileObj = document.getElementById('filebox_file_id_2').files[0];
			if(!fileObj) {
				$.messager.alert('提醒','请选择文件');
				return;
			}
			$.messager.progress({
				title : '提示',
				msg : '上传中，请稍候...'
			});
			var xhr = new XMLHttpRequest();
			xhr.open('POST', url + "/import");
			xhr.onload = function () {
		       if (xhr.status === 200) {
		    	    $.messager.progress('close');
			       	var resp = JSON.parse(xhr.response);
			       	if(resp.code == '000') {
			       		$.messager.alert("成功","上传成功！","info");
			       		dbObj.datagrid('reload');
			       		$('#files').filebox('setValue','');
			       		uploadBox.dialog('close');
			       	}else {
			       		$.messager.alert('错误提醒', resp.msg);
			       	}
		       }
		   };
		   xhr.onerror = function () {
			   $.messager.progress('close');
			   $.messager.alert('错误', "上传异常");
		   };
		   var fd = new FormData();
		   fd.append('files', fileObj);
		   // 触发上传
			setTimeout(function() {
				xhr.send(fd);
			}, 1000)
		}
		
    </script>
</body>
</html>